//
//  LBCategorySettingModel.m
//  AFNetworking
//
//  Created by luckyRoy on 2018/2/2.
//

#import "LBCategorySettingModel.h"
#import "LBCategoryViewController.h"

@interface LBCategorySettingModel ()

@property (nonatomic, strong) NSMutableArray *currentShowArray;

@property (nonatomic, strong) NSMutableArray <NSArray <LBCategoryModel *> *>*originalArray;

@end

@implementation LBCategorySettingModel

- (NSInteger)maxLevel
{
    if (!_maxLevel) {
        _maxLevel = 3;
    } else {
        if (_maxLevel < 2) {
            _maxLevel = 2;//最小两级
        }
        if (_maxLevel > 3) {
            _maxLevel = 3;//最大三级
        }
    }
    return _maxLevel;
}

- (LBCategoryCategoryChoseBackDircetion)choseDircetion
{
    if (!_choseDircetion) {
        _choseDircetion = LBCategoryCategoryChoseBackDircetionBack;
    }
    /*
     LBCategoryBizCodeTypeBookingRequirement = 1,//订阅需求
     LBCategoryBizCodeTypeBookingResource = 2,//订阅资源
     LBCategoryBizCodeTypeEnterResource = 3,//入驻资源
     LBCategoryBizCodeTypePublicRequirement = 4,//发布需求
     */
    if (LBCategoryBizCodeTypeBookingRequirement == self.codeType ||
        LBCategoryBizCodeTypeBookingResource == self.codeType ||
        LBCategoryBizCodeTypeEnterResource == self.codeType ||
        LBCategoryBizCodeTypePublicRequirement == self.codeType) {
        //向前跳转
        _choseDircetion = LBCategoryCategoryChoseBackDircetionForward;
    }
    
    return _choseDircetion;
}

- (NSMutableArray *)selectedModelArray
{
    if (!_selectedModelArray) {
        _selectedModelArray = [[NSMutableArray alloc]init];
    }
    return _selectedModelArray;
}

- (NSMutableArray *)threePageSelectedModelArray
{
    if (!_threePageSelectedModelArray) {
        _threePageSelectedModelArray = [[NSMutableArray alloc]init];
    }
    return _threePageSelectedModelArray;
}

- (NSMutableArray *)searchPageSelectedModelArray
{
    if (!_searchPageSelectedModelArray) {
        _searchPageSelectedModelArray = [[NSMutableArray alloc]init];
    }
    return _searchPageSelectedModelArray;
}

//- (NSMutableArray *)currentSelectedModelArray
//{
//    if (LBCategorySettingPageTypeHomePage == self.pageType) {
//        _currentSelectedModelArray = self.selectedModelArray;
//    } else if (LBCategorySettingPageTypeThreeLevel == self.pageType) {
//        _currentSelectedModelArray = self.threePageSelectedModelArray;
//    } else {
//        _currentSelectedModelArray = self.searchPageSelectedModelArray;
//    }
//    return _currentSelectedModelArray;
//}

- (void)setOriginalArrayByData:(NSArray *)modelArray
{
    self.originalArray = [NSMutableArray arrayWithArray:modelArray];
}

- (void)setCurrentShowArrayByData:(NSArray *)modelArray
{
    self.currentShowArray = [NSMutableArray arrayWithArray:modelArray];
}

- (NSMutableArray *)getOriginalArrayByOriginalData:(NSArray <LBCategoryModel *> *)originalData
{
    NSMutableArray *resultArray = [NSMutableArray array];
    
    [originalData enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull firobj, NSUInteger firidx, BOOL * _Nonnull firstop) {
        if (firobj.chirdrenNode.count) {

            [firobj.chirdrenNode enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull secondobj, NSUInteger secondidx, BOOL * _Nonnull secondstop) {
                //把父类logo传递给子类的父属性
                secondobj.parLogo = firobj.logo;
                
                [secondobj.chirdrenNode enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull threeobj, NSUInteger threeidx, BOOL * _Nonnull threestop) {
                    //把父类logo传递给子类的父属性
                    threeobj.parLogo = secondobj.logo;
                }];
            }];
            
            [resultArray addObject:firobj.chirdrenNode];
        }
    }];
    
    return resultArray;
}

- (void)addCategoryModel:(LBCategoryModel *)model currentPage:(LBCategorySettingPageType)page
{
    if (LBCategorySettingPageTypeHomePage == page) {
        if (self.isSingleSelected) {
            [self.selectedModelArray removeAllObjects];
        }
        //二级界面直接操作选中数组selectedModelArray
        if (![self containsCategoryCode:model.code fromSelectedArray:self.selectedModelArray]) {
            //非老数据就新增
            [self.selectedModelArray addObject:model];
        }
        if (self.homePageChangeBlock) {
            self.homePageChangeBlock();
        }
    } else if (LBCategorySettingPageTypeThreeLevel == page) {
        if (self.isSingleSelected) {
            [self.threePageSelectedModelArray removeAllObjects];
        }
        //三级界面操作选中状态 操作 threePageSelectedModelArray
        if (self.isSingleSelected) {
            //单选时 一选所有页面都有选中
            if (![self containsCategoryCode:model.code fromSelectedArray:self.selectedModelArray]) {
                //非老数据就新增
                [self addCategoryModel:model currentPage:LBCategorySettingPageTypeHomePage];
            }
        }
        //多选操作 threePageSelectedModelArray
        if (![self containsCategoryCode:model.code fromSelectedArray:self.threePageSelectedModelArray]) {
            [self.threePageSelectedModelArray addObject:model];
        }
        if (self.threeLevelChangeBlock) {
            self.threeLevelChangeBlock();
        }
    } else if (LBCategorySettingPageTypeSearchLevel == page) {
        if (self.isSingleSelected) {
            [self.searchPageSelectedModelArray removeAllObjects];
        }
        //三级界面操作选中状态 操作 searchPageSelectedModelArray
        if (![self containsCategoryCode:model.code fromSelectedArray:self.searchPageSelectedModelArray]) {
            //非老数据就新增
            [self.searchPageSelectedModelArray addObject:model];
        }
        if (self.isSingleSelected) {
            //单选时 一选所有页面都有选中
            if (![self containsCategoryCode:model.code fromSelectedArray:self.threePageSelectedModelArray]) {
                 [self addCategoryModel:model currentPage:LBCategorySettingPageTypeThreeLevel];
            }
        }
        if (self.searchLevelChangeBlock) {
            self.searchLevelChangeBlock();
        }
    }
}

- (void)onlyAddCategoryModel:(LBCategoryModel *)model currentPage:(LBCategorySettingPageType)page
{
    if (LBCategorySettingPageTypeHomePage == page) {
        if (self.isSingleSelected) {
            [self.selectedModelArray removeAllObjects];
        }
        //二级界面直接操作选中数组selectedModelArray
        if (![self containsCategoryCode:model.code fromSelectedArray:self.selectedModelArray]) {
            //非老数据就新增
            [self.selectedModelArray addObject:model];
        }
    } else if (LBCategorySettingPageTypeThreeLevel == page) {
        if (self.isSingleSelected) {
            [self.threePageSelectedModelArray removeAllObjects];
        }
        //三级界面操作选中状态 操作 threePageSelectedModelArray
        if (self.isSingleSelected) {
            //单选时 一选所有页面都有选中
            if (![self containsCategoryCode:model.code fromSelectedArray:self.selectedModelArray]) {
                //非老数据就新增
                [self addCategoryModel:model currentPage:LBCategorySettingPageTypeHomePage];
            }
        }
        //多选操作 threePageSelectedModelArray
        if (![self containsCategoryCode:model.code fromSelectedArray:self.threePageSelectedModelArray]) {
            [self.threePageSelectedModelArray addObject:model];
        }
    } else if (LBCategorySettingPageTypeSearchLevel == page) {
        if (self.isSingleSelected) {
            [self.searchPageSelectedModelArray removeAllObjects];
        }
        //三级界面操作选中状态 操作 searchPageSelectedModelArray
        if (![self containsCategoryCode:model.code fromSelectedArray:self.searchPageSelectedModelArray]) {
            //非老数据就新增
            [self.searchPageSelectedModelArray addObject:model];
        }
        if (self.isSingleSelected) {
            //单选时 一选所有页面都有选中
            if (![self containsCategoryCode:model.code fromSelectedArray:self.threePageSelectedModelArray]) {
                [self addCategoryModel:model currentPage:LBCategorySettingPageTypeThreeLevel];
            }
        }
    }
}

- (void)removeCategoryModel:(LBCategoryModel *)model currentPage:(LBCategorySettingPageType)page
{
    if (LBCategorySettingPageTypeHomePage == page) {
        self.selectedModelArray = [self newArrayByDelCode:model.code fromSelecedArray:self.selectedModelArray];
        if (self.homePageChangeBlock) {
            self.homePageChangeBlock();
        }
    } else if (LBCategorySettingPageTypeThreeLevel == page) {
        if (self.isSingleSelected) {
            //单选 删除等于添加
            [self addCategoryModel:model currentPage:page];
            if (self.threeLevelChangeBlock) {
                self.threeLevelChangeBlock();
            }
            return;
        }
        self.threePageSelectedModelArray = [self newArrayByDelCode:model.code fromSelecedArray:self.threePageSelectedModelArray];
        if (self.threeLevelChangeBlock) {
            self.threeLevelChangeBlock();
        }
    } else if (LBCategorySettingPageTypeSearchLevel == page) {
        //三级界面操作选中状态 操作 searchPageSelectedModelArray
        if (self.isSingleSelected) {
            [self.searchPageSelectedModelArray removeAllObjects];
        }
        self.searchPageSelectedModelArray = [self newArrayByDelCode:model.code fromSelecedArray:self.searchPageSelectedModelArray];
        if (self.searchLevelChangeBlock) {
            self.searchLevelChangeBlock();
        }
    }
}

- (void)onlyRemoveCategoryModel:(LBCategoryModel *)model currentPage:(LBCategorySettingPageType)page;
{
    if (LBCategorySettingPageTypeHomePage == page) {
        self.selectedModelArray = [self newArrayByDelCode:model.code fromSelecedArray:self.selectedModelArray];
    } else if (LBCategorySettingPageTypeThreeLevel == page) {
        if (self.isSingleSelected) {
            //单选 删除等于添加
            [self addCategoryModel:model currentPage:page];
            return;
        }
        self.threePageSelectedModelArray = [self newArrayByDelCode:model.code fromSelecedArray:self.threePageSelectedModelArray];
    } else if (LBCategorySettingPageTypeSearchLevel == page) {
        //三级界面操作选中状态 操作 searchPageSelectedModelArray
        self.searchPageSelectedModelArray = [self newArrayByDelCode:model.code fromSelecedArray:self.searchPageSelectedModelArray];
    }
}

- (NSMutableArray *)newArrayByDelCode:(NSString *)delCode fromSelecedArray:(NSArray *)array
{
    if (!delCode.length) {
        return [NSMutableArray array];
    }
    NSMutableArray *newSelectedArray = [NSMutableArray arrayWithArray:array];
    NSMutableArray *tempArray = [NSMutableArray arrayWithArray:array];
    [tempArray enumerateObjectsUsingBlock:^(LBCategoryModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.code isEqualToString:delCode]) {
            [newSelectedArray removeObjectAtIndex:idx];
            *stop = YES;
        }
    }];
    
    return newSelectedArray;
}

//- (void)removeCategoryModelArray:(NSArray *)modelArray
//{
//    if (!modelArray.count) {
//        return;
//    }
//    NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.selectedModelArray];
//    NSMutableArray *totalSelectedArray = [NSMutableArray array];
//    [tempArray enumerateObjectsUsingBlock:^(LBCategoryModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        BOOL isRemove = NO;
//        for (LBCategoryModel *model in modelArray) {
//            if ([obj.code isEqualToString:model.code]) {
//                isRemove = YES;
//            }
//        }
//        if (!isRemove) {
//            [totalSelectedArray addObject:obj];
//        }
//    }];
//    self.selectedModelArray = [NSMutableArray arrayWithArray:totalSelectedArray];
//    if (self.changeBlock) {
//        self.changeBlock();
//    }
//
//    if (self.allChangeBlock) {
//        self.allChangeBlock();
//    }
//}

//- (void)removeCategoryByCodeArray:(NSArray *)codeArray
//{
//    if (!codeArray.count) {
//        return;
//    }
//    NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.selectedModelArray];
//    NSMutableArray *totalSelectedArray = [NSMutableArray array];
//    [tempArray enumerateObjectsUsingBlock:^(LBCategoryModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        BOOL isRemove = NO;
//        for (NSString *code in codeArray) {
//            if ([obj.code isEqualToString:code]) {
//                isRemove = YES;
//            }
//        }
//        if (!isRemove) {
//            [totalSelectedArray addObject:obj];
//        }
//    }];
//    self.selectedModelArray = [NSMutableArray arrayWithArray:totalSelectedArray];
//}

- (BOOL)containsCategoryCode:(NSString *)code fromSelectedArray:(NSArray *)selectedArray
{
    if (!code) {
        return NO;
    }
    
    __block BOOL isSelected = NO;
    
    [selectedArray enumerateObjectsUsingBlock:^(LBCategoryModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.code isEqualToString:code]) {
            isSelected = YES;
            *stop = YES;
        }
    }];
    
    return isSelected;
}

- (BOOL)isShowNextLevel:(NSInteger)currentLevel
{
    BOOL isShowNextStep = NO;
    
    NSInteger maxLevel = self.maxLevel;
    
    if (currentLevel < maxLevel) {
        isShowNextStep = YES;
    }
    
    return isShowNextStep;
}

- (void)dealWithSelectedArrayFromPage:(LBCategorySettingPageType)fromPage
                               toPage:(LBCategorySettingPageType)toPage
{
    if (LBCategorySettingPageTypeHomePage == toPage) {
        if (LBCategorySettingPageTypeThreeLevel == fromPage) {
            self.selectedModelArray = [self getCopyByOriginalData:self.threePageSelectedModelArray];
        } else if (LBCategorySettingPageTypeSearchLevel == fromPage) {
            self.selectedModelArray = [self getCopyByOriginalData:self.searchPageSelectedModelArray];
        }
        if (self.homePageChangeBlock) {
            self.homePageChangeBlock();
        }
    } else if (LBCategorySettingPageTypeThreeLevel == toPage) {
        if (LBCategorySettingPageTypeHomePage == fromPage) {
            self.threePageSelectedModelArray = [self getCopyByOriginalData:self.selectedModelArray];
        } else if (LBCategorySettingPageTypeSearchLevel == fromPage) {
            self.threePageSelectedModelArray = [self getCopyByOriginalData:self.searchPageSelectedModelArray];
        }
        if (self.threeLevelChangeBlock) {
            self.threeLevelChangeBlock();
        }
    } else if (LBCategorySettingPageTypeSearchLevel == toPage) {
        if (LBCategorySettingPageTypeHomePage == fromPage) {
            self.searchPageSelectedModelArray = [self getCopyByOriginalData:self.selectedModelArray];
        } else if (LBCategorySettingPageTypeThreeLevel == fromPage) {
            self.searchPageSelectedModelArray = [self getCopyByOriginalData:self.threePageSelectedModelArray];
        }
        if (self.searchLevelChangeBlock) {
            self.searchLevelChangeBlock();
        }
    }
}

- (BOOL)isShowTopSelectedView
{
    return [self isBookingCodeType];
}

- (BOOL)isBookingCodeType
{
    BOOL isBooking = NO;
    if (LBCategoryBizCodeTypeBookingRequirement ==self.codeType ||
        LBCategoryBizCodeTypeBookingResource ==self.codeType) {
        //订阅 展示搜索 顶部选择
        isBooking = YES;
    }
    
    return isBooking;
}

- (NSMutableArray *)getSearchAllModel
{
    NSMutableArray *copyArray = [NSMutableArray array];
    
    [self.originalArray enumerateObjectsUsingBlock:^(NSArray<LBCategoryModel *> * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull twoLevelobj, NSUInteger twoLevelidx, BOOL * _Nonnull twoLevelstop) {
            if (twoLevelobj.chirdrenNode.count && self.maxLevel > 2 && ![self isBookingCodeType]) {
                //三级有数据 且 最大级大于2级 且 非订阅类型(订阅不搜索三级)
                [twoLevelobj.chirdrenNode enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull threeLevelobj, NSUInteger threeLevelidx, BOOL * _Nonnull threeLevelstop) {
                    [copyArray addObject:[threeLevelobj copy]];
                }];
            } else {
                [copyArray addObject:[twoLevelobj copy]];
            }
        }];
        
    }];

    return copyArray;
}

+ (NSMutableArray *)selectedModelArrayFromCodeArray:(NSArray *)codeArray
                                         totalArray:(NSArray *)totalArray
                                   isSingleSelected:(BOOL)isSingleSelected
{
    NSMutableArray *resultArray = [NSMutableArray array];
    if (!codeArray.count) {
        return resultArray;
    }
    __weak __typeof(&*self)weakSelf = self;
    
    [totalArray enumerateObjectsUsingBlock:^(LBCategoryModel *oneLevelArray, NSUInteger oneLevelidx, BOOL * _Nonnull oneLevelstop) {
        [oneLevelArray.chirdrenNode enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull twoLevelobj, NSUInteger twoLevelidx, BOOL * _Nonnull twoLevelstop) {
            if ([codeArray containsObject:twoLevelobj.code] &&
                ![weakSelf containsCategoryCode:twoLevelobj.code selectedModelArray:resultArray]) {
                if (isSingleSelected) {
                    [resultArray removeAllObjects];
                }
                [resultArray addObject:twoLevelobj];
            }
            [twoLevelobj.chirdrenNode enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull threeLevelobj, NSUInteger threeLevelidx, BOOL * _Nonnull threeLevelstop) {
                if ([codeArray containsObject:threeLevelobj.code] &&
                    ![weakSelf containsCategoryCode:threeLevelobj.code selectedModelArray:resultArray]) {
                    if (isSingleSelected) {
                        [resultArray removeAllObjects];
                    }
                    [resultArray addObject:threeLevelobj];
                }
            }];
        }];
    }];
    
    return resultArray;
}

+ (NSMutableArray *)getListModelBySettingModel:(LBCategorySettingModel *)settingModel
                                   currentPage:(LBCategorySettingPageType)page
{
    NSMutableArray *resultArray = [NSMutableArray array];

    if (LBCategorySettingPageTypeHomePage == page) {
        
        if (settingModel.isShowAll) {
            //展示自定义全部分类
            LBCategoryModel *addModel = [[LBCategoryModel alloc]init];
            addModel.isAllAll = YES;
            //没有默认选中 默认选中全部
            if (!settingModel.selectedModelArray.count) {
                addModel.isSelected = YES;
            }
            [resultArray addObject:@[addModel]];
        }
        
        //二级分类
        if ([settingModel isShowTopSelectedView]) {
            [resultArray addObject:[NSMutableArray arrayWithArray:settingModel.selectedModelArray]];
            [settingModel.selectedModelArray enumerateObjectsUsingBlock:^(LBCategoryModel   *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.isChosedCell = YES;
                obj.isEdiotr = settingModel.isEdiotr;
                obj.isSelected = YES;
            }];
        }
        [settingModel.originalArray enumerateObjectsUsingBlock:^(NSArray<LBCategoryModel *> * _Nonnull firArray, NSUInteger firidx, BOOL * _Nonnull firstop) {
            
            NSMutableArray *tmpArray = [NSMutableArray array];
            
            if (settingModel.isShowAll && ![firArray firstObject].isAll) {
                //需要展示全部
                LBCategoryModel *allModel = [self getCustomAllModelByModel:[firArray lastObject]];
                if ([settingModel containsCategoryCode:allModel.code fromSelectedArray:settingModel.selectedModelArray]) {
                    allModel.isSelected = YES;
                } else {
                    allModel.isSelected = NO;
                }
                [tmpArray addObject:allModel];
            }
            
            [firArray enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //给子类添加父类的icon 便于段头展示
                if ([settingModel containsCategoryCode:obj.code fromSelectedArray:settingModel.selectedModelArray]) {
                    obj.isSelected = YES;
                } else {
                    obj.isSelected = NO;
                }
                
                if ([settingModel isShowTopSelectedView]) {
                    //展示顶部选中时 二级被选中在列表中不展示
                    if (!obj.isSelected) {
                        obj.isChosedCell = NO;
                        obj.isEdiotr = NO;
                        [tmpArray addObject:obj];
                    }
                } else {
                    obj.isChosedCell = NO;
                    obj.isEdiotr = NO;
                    [tmpArray addObject:obj];
                }
  
                [obj.chirdrenNode enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull lastobj, NSUInteger lastidx, BOOL * _Nonnull laststop) {
                    if ([settingModel containsCategoryCode:lastobj.code fromSelectedArray:settingModel.selectedModelArray]) {
                        //子类被选中 父类默认选中
                        obj.isSelected = YES;
                    }
                }];
                
            }];
            
            if (tmpArray.count) {
                [resultArray addObject:tmpArray];
            }
        }];
    } else if (LBCategorySettingPageTypeThreeLevel == page)  {
        if (!settingModel.currentShowArray) {
            return resultArray;
        }
        NSMutableArray *tmpArray = [NSMutableArray array];
        LBCategoryModel *firstModel = [settingModel.currentShowArray firstObject];
        if (settingModel.isShowAll && !firstModel.isAll) {
            //需要展示全部
            [tmpArray addObject:[self getCustomAllModelByModel:[settingModel.currentShowArray lastObject]]];
        }
        [settingModel.currentShowArray enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([settingModel containsCategoryCode:obj.code fromSelectedArray:settingModel.threePageSelectedModelArray]) {
                obj.isSelected = YES;
            } else {
                obj.isSelected = NO;
            }
            [tmpArray addObject:obj];
        }];
        [resultArray addObject:tmpArray];
    } else {
        if (!settingModel.currentShowArray) {
            return resultArray;
        }
        NSMutableArray *tmpArray = [NSMutableArray array];
        LBCategoryModel *firstModel = [settingModel.currentShowArray firstObject];
        if (settingModel.isShowAll && !firstModel.isAll) {
            //需要展示全部
            [tmpArray addObject:[self getCustomAllModelByModel:[settingModel.currentShowArray lastObject]]];
        }
        [settingModel.currentShowArray enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([settingModel containsCategoryCode:obj.code fromSelectedArray:settingModel.searchPageSelectedModelArray]) {
                obj.isSelected = YES;
            } else {
                obj.isSelected = NO;
            }
            [tmpArray addObject:obj];
        }];
        [resultArray addObject:tmpArray];
    }
    return resultArray;
}

+ (LBCategoryModel *)getCustomAllModelByModel:(LBCategoryModel *)model
{
    //第一个选项不是全部
    LBCategoryModel *addModel = [[LBCategoryModel alloc]init];
    addModel.isAll = YES;
    addModel.name = model.parName;
    addModel.code = model.parCode;
    return addModel;
}

+ (BOOL)containsCategoryCode:(NSString *)code selectedModelArray:(NSMutableArray *)selectedArray
{
    if (!code) {
        return NO;
    }
    
    __block BOOL isSelected = NO;
    
    [selectedArray enumerateObjectsUsingBlock:^(LBCategoryModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.code isEqualToString:code]) {
            isSelected = YES;
            *stop = YES;
        }
    }];
    
    return isSelected;
}

//- (void)dealWithRealSelectedByCancelCodeArray:(NSArray *)codeArray
//                           selectedModelArray:(NSArray *)selectedModelArray
//{
//    [self removeCategoryByCodeArray:codeArray];
//    [self addCategoryModelArray:selectedModelArray];
//    
//    if (self.changeBlock) {
//        self.changeBlock();
//    }
//}

+ (BOOL)isBookingViewByCodeType:(LBCategoryBizCodeType)codeType
{
    BOOL isBookingView = NO;
    if (LBCategoryBizCodeTypeBookingRequirement == codeType ||
        LBCategoryBizCodeTypeBookingResource == codeType) {
        isBookingView = YES;
    }
    return isBookingView;
}

+ (NSMutableArray *)getCopyByOriginalData:(NSArray <LBCategoryModel *> *)originalData
{
    NSMutableArray *copyArray = [NSMutableArray array];
    
    [originalData enumerateObjectsUsingBlock:^(LBCategoryModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [copyArray addObject:[obj copy]];
    }];

    return copyArray;
}

- (NSMutableArray *)getCopyByOriginalData:(NSMutableArray *)originalData {
    return [self.class getCopyByOriginalData:originalData];
}

@end
